<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="file" name="img">
  <progress value=0 max=100></progress>
  <span class="progress-text">0%</span>
  <span class="up-speed">0kb/s</span>
  <button id="start">开始上传</button>
  <button id="cancel">取消上传</button>

  <script>
    // 创建xhr对象
    const xhr = new XMLHttpRequest()

    start.onclick = function () {
      const uploadImg = document.querySelector("input").files[0]
      // 创建表单对象
      const formObj = new FormData()
      // 使用 append() 添加数据
      formObj.append("myImg", uploadImg)
      formObj.append("username", "zhangsan")

      xhr.open("post", "/upload", true)

      // xhr.upload.

      xhr.send(formObj)

    }
  </script>
</body>

</html>
